<template>
	<view class="content">
		<!-- 待用活动表单1 -->
		<active-form :formDate="formDate1" @input-val="inputVal1"  :head="head">
		</active-form>
		<view :style="bj" class="buttonBox" @click="submit1">
			编辑完成
		</view>
	</view>
	</view>
</template>

<script>
	import activeForm from './../../components/active_form.vue';
	export default {
		components: {
			activeForm
		},
		data() {
			return {
				formDate1: [],
				barcodes: [],
				head:[],
				bj:{
				backgroundColor:this.$kdup.color,
				},
			}
		},
		onLoad(e) {
			uni.setNavigationBarColor({
				frontColor: "#ffffff",	//文字颜色
				backgroundColor: this.$kdup.color	//底部背景色
			})
			var obj = JSON.parse(e.smallbars);
			this.head = JSON.parse(e.head);
			
			var initData = []
			for (var i = 0; i < obj.length; i++) {
				initData.push({
					placeholder: "请输条码", //提示
					label: "条码" + (i + 1), //标题
					type: "text", //类型ffieldtype
					disabled: true, //是否启用
					maxlength: "-1", //输入长度
					property: {
						fishidden: 0
					},
					key: "", //唯一标识
					rules: {
						flag: 0, //标识
						name: "barcode" + (i + 1), //名称fkey
						value: obj[i].fnumber, //显示值
						rowvalue: obj[i],
						verify: "", //必录fmustinput
						errMess: "请输入条码" //非空提示
					}
				}, {
					placeholder: "请输入数量", //提示
					label: "数量" + (i + 1), //标题
					type: "number", //类型ffieldtype
					disabled: false, //是否启用
					maxlength: "-1", //输入长度
					property: {
						ffieldtype: 0,
						fishidden: 0
					}, //配置属性
					key: "fqty", //唯一标识
					rules: {
						flag: 999, //标识
						name: "fqty" + (i + 1), //名称fkey
						value: parseFloat(obj[i].fqty), //显示值
						rowvalue: obj[i],
						verify: "", //必录fmustinput
						errMess: "请输入数量" //非空提示
					}
				}, {
					placeholder: "请输入辅助数量", //提示
					label: "辅助数量" + (i + 1), //标题
					type: "number", //类型ffieldtype
					disabled: true, //是否启用
					maxlength: "-1", //输入长度
					property: {
						fishidden: 0
					},
					key: "", //唯一标识
					rules: {
						flag: 1000, //标识
						name: "fauxunitqty" + (i + 1), //名称fkey
						value: parseFloat(obj[i].fauxinvqty), //显示值
						rowvalue: obj[i],
						verify: "", //必录fmustinput
						errMess: "请输入辅助数量" //非空提示
					}
				})
			}
			initData[initData.length - 1].rules.flag = 0;
			this.formDate1 = initData;
		},
		methods: {
			//设置页签1表单的值
			inputVal1: function(data) {
				var data = JSON.parse(data);
				if (String(data.val) != "" && String(data.index) != "") {
					this.formDate1[data.index].rules.value = data.val;
					if (String(data.rowvalue) != "" || String(data.rowvalue) != null) {
						this.formDate1[data.index].rules.rowvalue.fqty = data.rowvalue.id;
					}
				}
			},
			submit1: function() {
				var otherPra = {
					reqEmptyVal: true,
				}
				if (this.$vervify({
						formDate: this.formDate1,
						otherPra: otherPra
					})) {
					var sum = 0;
					for (var i = 0; i < this.formDate1.length; i++) {
						if (this.formDate1[i].disabled == false) {
							sum += parseFloat(this.formDate1[i].rules.value)
						}
						if (this.formDate1[i].key == "fqty") {
							this.barcodes.push(this.formDate1[i]);
						}
					}
					const pages = getCurrentPages(); //当前页
					const beforePage = pages[pages.length - 2]; //上个页面
					if (isNaN(sum)) {
						sum = 0;
					}
					var data = {
						array: this.barcodes,
						sum: sum
					}
					beforePage.$vm.smallBarsres(data);
					uni.navigateBack({
						delta: 1
					});
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}

	.buttonBox {
		width: 100%;
		height: 84upx;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 999;
	}
</style>
